from core.support import set_cutscene, get_game
from core.item import Item
from core.action import Action

class GrapplingGun(Item):
    def __init__(self):
        Item.__init__(self, "GrapplingGun")    
        self.has_hook = True
    
        self.add_action(Shoot)
        
    def get_description(self):
        return "Grappling Gun"

class Shoot(Action):
    def __init__(self):
        Action.__init__(self, "shoot_it")
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Shoot the Grappling Gun"
    
    def do_action(self,game,room,request):
        game = get_game()
        player = game.get_player()
        if room.get_id() == 'lookdown2' and player.has_status("knows_escape_plan"):
            player.add_status("hooked_in")
            set_cutscene("NAILED IT! You pull the trigger, and the grappling hook flies through the air, lodging itself in the far wall. It feels strong enough to hold your weight.")
            self.item.has_hook = False
        else:
            set_cutscene("You pull the trigger, and the grappling hook flies through the air, lodging into a nearby wall. After struggling for a few minutes, you retrieve it and load it back into the gun.")
        return
    
    def get_method(self):
        return "post"
    
    def is_enabled(self):
        if self.item.has_hook:
            return True
        else:
            return False